
import { reqGoodinfo,reqAddshopcart } from "../../api"
//封装游客临时身份模块uuid    --生成一个随机的字符串(只获取一次s)
import { getUUID} from '../../utils/uuid_token'
const state={ 
    goodinfo:{},
    //游客的临时身份
    uuid_token: getUUID()
}
const mutations={
    GETGOODINFO(state,data){
        state.goodinfo=data
    }
}
const actions={
    //获取产品信息
    async getGoodinfo({commit},skuId){
        let result=await reqGoodinfo(skuId)
        if(result.code==200){
            commit('GETGOODINFO',result.data)
        }
    },
    //添加购物车
    async addShopcart({commit},{skuId,skuNum}){
        let result= await reqAddshopcart(skuId,skuNum)
        if(result.code==200){
            return "ok";
        }else{
            return Promise.reject(new Error('faile'))
        }
    }
}
const getters={
    categoryView(state){
        return state.goodinfo.categoryView||{}
    },
    skuInfo(state){
        return state.goodinfo.skuInfo||{}
    },
    spuSaleAttrList(state){
        return state.goodinfo.spuSaleAttrList||[]
    }
}
export default{
    state,
    mutations,
    actions,
    getters
}